package com.gmq.mianshi.designModel.singleton;

/**
 * @author gmq
 * @email 2628931@qq.com
 * @date 2017/11/23 11:10
 */
public class TestSingleton {

    private String name = null;

    // 私有化构造器
    private TestSingleton() {

    }

    // 饿汉
    private static volatile TestSingleton singleton = null;

    // 双重检测
    public static TestSingleton getInstance() {
        if (singleton == null) {
            synchronized (TestSingleton.class) {
                if (singleton == null) {
                    singleton = new TestSingleton();
                }
            }
        }

        return singleton;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void printInfo() {
        System.out.println("the name is " + name);
    }
}
